﻿using System;
using System.Text;
using System.Data;

using LTJ.Common.Generic;
using LTJ.Entity;
using LTJ.Common;
using LTJ.Config;

namespace LTJ.Data.DataProvider
{
    /// <summary>
    /// 日志操作
    /// </summary>
    public class OpLogs
    {
        /// <summary>
        /// 创建访问日志
        /// </summary>
        /// <param name="uid">用户ID</param>
        /// <param name="lname">登录名</param>
        /// <param name="gid">组ID</param>
        /// <param name="cid">访问企业ID</param>
        /// <param name="ip">访问IP</param>
        /// <param name="actid">访问动作</param>
        /// <param name="actdesc">具体内容描述</param>
        /// <returns>日志ID</returns>
        public static int CreateVisitLog(int uid, string lname, int gid, int cid, string ip, int actid, string actstr, string actdesc)
        {
            return Data.DatabaseProvider.GetInstance().CreateVisitLog(uid, lname, gid, cid, ip, actid, actstr, actdesc);
        }

        /// <summary>
        /// 根据条件获取全部企业管理员访问日志集合数量
        /// </summary>
        public static int GetAllCompanyVisitLogCount(string querystring)
        {
            return Data.DatabaseProvider.GetInstance().GetAllCompanyVisitLogCount(querystring);
        }

        /// <summary>
        /// 获取全部企业管理员访问日志分页操作
        /// </summary>
        public static DataTable GetAllCompanyVisitLogsByPage(int pageindex, int pagesize, string condition, string ordercolumn, string ordertype)
        {
            return Data.DatabaseProvider.GetInstance().GetAllCompanyVisitLogsByPage(pageindex, pagesize, condition, ordercolumn, ordertype);
        }

        /// <summary>
        /// 删除访问日志
        /// </summary>
        public static void DelVisitLog(string ids)
        {
            Data.DatabaseProvider.GetInstance().DelVisitLog(ids);
        }

        /// <summary>
        /// 创建线路信息日志
        /// </summary>
        /// <param name="uid">用户ID</param>
        /// <param name="lname">登录名</param>
        /// <param name="rid">新增线路ID</param>
        /// <param name="price1">20GP</param>
        /// <param name="price2">40GP</param>
        /// <param name="price3">40HQ</param>
        /// <param name="actid">动作ID</param>
        /// <param name="logstr">动作描述</param>
        public static int CreateRouteLog(int uid, string lname, int rid, string price1, string price2, string price3, int actid, string actstr, string actdesc)
        {
            return Data.DatabaseProvider.GetInstance().CreateRouteLog(uid, lname, rid, price1, price2, price3, actid, actstr, actdesc);
        }
        /// <summary>
        /// 根据条件获取全部企业线路操作日志集合数量
        /// </summary>
        public static int GetAllRouteLogCount(string querystring)
        {
            return Data.DatabaseProvider.GetInstance().GetAllRouteLogCount(querystring);
        }

        /// <summary>
        /// 获取全部企业线路操作日志分页操作
        /// </summary>
        public static DataTable GetRouteLogsByPage(int pageindex, int pagesize, string condition, string ordercolumn, string ordertype)
        {
            return Data.DatabaseProvider.GetInstance().GetRouteLogsByPage(pageindex, pagesize, condition, ordercolumn, ordertype);
        }
        /// <summary>
        /// 删除线路操作日志
        /// </summary>
        public static void DelRouteLogs(string ids)
        {
            Data.DatabaseProvider.GetInstance().DelRouteLogs(ids);
        }
        /// <summary>
        /// 根据条件获取线路日志集合
        /// </summary>
        public static DataTable GetRouteLogTable(string conditions)
        {
            return Data.DatabaseProvider.GetInstance().GetRouteLogTable(conditions);
        }
        /// <summary>
        /// 根据条件获取线路日志集合
        /// </summary>
        public static List<RouteLogInfo> GetRouteLogs(string conditions)
        {
            return LoadRouteLogsInfo(Data.DatabaseProvider.GetInstance().GetRouteLogReader(conditions));
        }
        /// <summary>
        /// 创建规则日志
        /// </summary>
        /// <param name="uid">用户ID</param>
        /// <param name="lname">登录名</param>
        /// <param name="cid">规则所属公司</param>
        /// <param name="rid">规则ID</param>
        /// <param name="price1">20GP</param>
        /// <param name="price2">40GP</param>
        /// <param name="price3">40HQ</param>
        /// <param name="actid">动作ID</param>
        /// <param name="actdesc">动作描述</param>
        public static int CreateRuleLog(int uid, string lname, int cid, int rid, string price1, string price2, string price3, int actid, string actstr, string actdesc)
        {
            return Data.DatabaseProvider.GetInstance().CreateRuleLog(uid, lname, cid, rid, price1, price2, price3, actid, actstr, actdesc);
        }
        /// <summary>
        /// 根据条件获取全部企业规则操作日志集合数量
        /// </summary>
        public static int GetAllRuleLogCount(string querystring)
        {
            return Data.DatabaseProvider.GetInstance().GetAllRuleLogCount(querystring);
        }
        /// <summary>
        /// 获取全部企业规则操作日志分页操作
        /// </summary>
        public static DataTable GetRuleLogsByPage(int pageindex, int pagesize, string condition, string ordercolumn, string ordertype)
        {
            return Data.DatabaseProvider.GetInstance().GetRuleLogsByPage(pageindex, pagesize, condition, ordercolumn, ordertype);
        }
        /// <summary>
        /// 删除规则操作日志
        /// </summary>
        public static void DelRuleLogs(string ids)
        {
            Data.DatabaseProvider.GetInstance().DelRuleLogs(ids);
        }

        /// <summary>
        /// 创建用户搜索日志
        /// </summary>
        /// <param name="uid">用户ID（-1为匿名用户）</param>
        /// <param name="lname">登录名</param>
        /// <param name="visitip">访问IP</param>
        /// <param name="stype">搜索类型（默认0为整柜）</param>
        /// <param name="dportkey">目的港关键字</param>
        /// <param name="lportkey">起运港关键字</param>
        /// <param name="routeline">航线</param>
        /// <param name="boatcorp">船公司</param>
        /// <param name="oid">对象ID（整柜为线路ID）</param>
        /// <param name="actid">动作ID</param>
        /// <param name="actions">动作名称</param>
        /// <param name="acotent">动作内容</param>
        /// <param name="searchcode">编号（整柜指线路编号）</param>
        /// <returns>日志ID</returns>
        public static int CreateUserVisitLog(int uid, string lname, string visitip, int stype, string dportkey, string lportkey, string routeline, string boatcorp, int oid, int actid, string actions, string acotent, string searchcode)
        {
            return Data.DatabaseProvider.GetInstance().CreateUserVisitLog(uid, lname, visitip, stype, dportkey, lportkey, routeline, boatcorp, oid, actid, actions, acotent, searchcode);
        }

        /// <summary>
        /// 根据条件获取用户搜索日志集合
        /// </summary>
        public static int GetAllUserVisitLogCount(string querystring)
        {
            return Data.DatabaseProvider.GetInstance().GetAllUserVisitLogCount(querystring);
        }
        /// <summary>
        /// 获取全部用户搜索日志分页操作
        /// </summary>
        public static DataTable GetAllUserVisitLogsByPage(int pageindex, int pagesize, string condition, string ordercolumn, string ordertype)
        {
            return Data.DatabaseProvider.GetInstance().GetAllUserVisitLogsByPage(pageindex, pagesize, condition, ordercolumn, ordertype);
        }

        /// <summary>
        /// 删除用户搜索操作日志
        /// </summary>
        public static void DelUserVisitLogs(string ids)
        {
            Data.DatabaseProvider.GetInstance().DelUserVisitLogs(ids);
        }
        #region Helper
        private static List<RouteLogInfo> LoadRouteLogsInfo(IDataReader reader)
        {
            List<RouteLogInfo> rblist = new List<RouteLogInfo>();
            while (reader.Read())
            {
                RouteLogInfo _info = new RouteLogInfo();
                _info.id = TypeConverter.ObjectToInt(reader["id"], 0);
                _info.uid = TypeConverter.ObjectToInt(reader["uid"], 0);
                _info.lname = reader["lname"].ToString();
                _info.rid = TypeConverter.ObjectToInt(reader["rid"], 0);
                _info.createdate = reader["createdate"].ToString();
                _info._20GP = reader["20GP"].ToString();
                _info._40GP = reader["40GP"].ToString();
                _info._40HQ = reader["40HQ"].ToString();
                _info.actions = reader["actions"].ToString();
                _info.others = reader["others"].ToString();
                _info.actid = TypeConverter.ObjectToInt(reader["actid"], 0);
                rblist.Add(_info);
            }
            reader.Close();
            return rblist;
        }
        #endregion
    }
}
